home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / acodet1a / form1.frm (.txt) next >
Encoding:
Visual Basic Form  |  1998-06-25  |  7.2 KB  |  182 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    ClientHeight    =   3195
  4.    ClientLeft      =   60
  5.    ClientTop       =   60
  6.    ClientWidth     =   4770
  7.    ControlBox      =   0   'False
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   3195
  10.    ScaleWidth      =   4770
  11.    ShowInTaskbar   =   0   'False
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin VB.ListBox List1 
  14.       Height          =   1980
  15.       IntegralHeight  =   0   'False
  16.       ItemData        =   "Form1.frx":0000
  17.       Left            =   405
  18.       List            =   "Form1.frx":0019
  19.       TabIndex        =   0
  20.       Top             =   540
  21.       Width           =   2445
  22.    End
  23.    Begin Project1.FormDragger FormDragger1 
  24.       Align           =   1  'Align Top
  25.       Height          =   285
  26.       Left            =   0
  27.       Top             =   0
  28.       Width           =   4770
  29.       _ExtentX        =   8414
  30.       _ExtentY        =   503
  31.       Caption         =   "Docking Window Example"
  32.       RepositionForm  =   0   'False
  33.    End
  34. Attribute VB_Name = "Form1"
  35. Attribute VB_GlobalNameSpace = False
  36. Attribute VB_Creatable = False
  37. Attribute VB_PredeclaredId = True
  38. Attribute VB_Exposed = False
  39. Option Explicit
  40. 'Public variables used elsewhere to set values for this form's position
  41. 'and size.
  42. Dim lFloatingWidth As Long
  43. Dim lFloatingHeight As Long
  44. Dim lFloatingLeft As Long
  45. Dim lFloatingTop As Long
  46. Dim bMoving As Boolean
  47. 'Private variables used to track moving/sizing etc.
  48. Public bDocked As Boolean
  49. Public lDockedWidth As Long
  50. Public lDockedHeight As Long
  51. Private Sub Form_Load()
  52.     'Initialize the positions/sizes of this form
  53.     lDockedWidth = MDIForm1.Picture1.ScaleWidth + (8 * Screen.TwipsPerPixelX)
  54.     lDockedHeight = MDIForm1.Picture1.ScaleHeight + (8 * Screen.TwipsPerPixelY)
  55.     lFloatingLeft = Me.Left
  56.     lFloatingTop = Me.Top
  57.     lFloatingWidth = Me.Width
  58.     lFloatingHeight = Me.Height
  59.     'Start with the form docked in Picture1 on the MDI Form
  60.     'put Form1 in the 'Dock' and position it so its resizing border is
  61.     'hidden outside the confines of Picture1
  62.     bDocked = True
  63.     SetParent Me.hwnd, MDIForm1!Picture1.hwnd
  64.     Me.Move -4 * Screen.TwipsPerPixelX, -4 * Screen.TwipsPerPixelY, lDockedWidth, lDockedHeight
  65.     MDIForm1!Picture1.Visible = True
  66. End Sub
  67. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  68.     'reset this form's owner to prevent a crash
  69.     Call SetWindowWord(Me.hwnd, SWW_HPARENT, 0&)
  70. End Sub
  71. Private Sub Form_Resize()
  72.     If Me.WindowState <> vbMinimized Then
  73.         'Update the stored Values
  74.         StoreFormDimensions
  75.         'position and size the listbox
  76.         List1.Move 3 * Screen.TwipsPerPixelX, FormDragger1.Height + (3 * Screen.TwipsPerPixelY), Me.ScaleWidth - (7 * Screen.TwipsPerPixelX), Me.ScaleHeight - (FormDragger1.Height + (6 * Screen.TwipsPerPixelY))
  77.     End If
  78. End Sub
  79. Private Sub FormDragger1_DblClick()
  80.     'Snap the form in or out of the dock (Picture1)
  81.     bMoving = True 'stop the new dimensions being stored
  82.     If bDocked Then
  83.         'Undock
  84.         Me.Visible = False
  85.         bDocked = False
  86.         SetParent Me.hwnd, 0
  87.         Me.Move lFloatingLeft, lFloatingTop, lFloatingWidth, lFloatingHeight
  88.         MDIForm1!Picture1.Visible = False
  89.         Me.Visible = True
  90.         'make this form 'float' above the MDI form
  91.         Call SetWindowWord(Me.hwnd, SWW_HPARENT, MDIForm1.hwnd)
  92.     Else
  93.         'Dock
  94.         bDocked = True
  95.         SetParent Me.hwnd, MDIForm1!Picture1.hwnd
  96.         Me.Move -4 * Screen.TwipsPerPixelX, -4 * Screen.TwipsPerPixelY, lDockedWidth, lDockedHeight
  97.         MDIForm1!Picture1.Visible = True
  98.     End If
  99.     bMoving = False
  100. End Sub
  101. Private Sub FormDragger1_FormDropped(FormLeft As Long, FormTop As Long, FormWidth As Long, FormHeight As Long)
  102.     Dim rct As RECT
  103.     'If over Picture1 on MDIForm1 which we are using as a Dock, set parent
  104.     'of this form to Picture1, and position it at -4,-4 pixels, otherwise
  105.     'set this Form's parent to the desktop and postion it at Left,Top
  106.     'We dont need to size the form, as the DragForm control will have done
  107.     'this for us.
  108.     'For the purposes of this example, we only dock if the top left corner
  109.     'of this form is within the area bounded by Picture1
  110.     'Get the screen based coordinates of Picture1
  111.     GetWindowRect MDIForm1!Picture1.hwnd, rct
  112.     'Inflate the rect because we want the form to be bigger than Picture1
  113.     'to hide it's border
  114.     With rct
  115.         .Left = .Left - 4
  116.         .Top = .Top - 4
  117.         .Right = .Right + 4
  118.         .Bottom = .Bottom + 4
  119.     End With
  120.     'See if the top/left corner of this form is in Picture1's screen rectangle
  121.     'As we have set RepositionForm to false, we are responsible for positioning the form
  122.     If PtInRect(rct, FormLeft, FormTop) Then
  123.         bDocked = True
  124.         SetParent Me.hwnd, MDIForm1!Picture1.hwnd
  125.         Me.Move -4 * Screen.TwipsPerPixelX, -4 * Screen.TwipsPerPixelY, lDockedWidth, lDockedHeight
  126.         MDIForm1!Picture1.Visible = True
  127.     Else
  128.         Me.Visible = False
  129.         bDocked = False
  130.         SetParent Me.hwnd, 0
  131.         Me.Move FormLeft * Screen.TwipsPerPixelX, FormTop * Screen.TwipsPerPixelY, lFloatingWidth, lFloatingHeight
  132.         MDIForm1!Picture1.Visible = False
  133.         Me.Visible = True
  134.         'make this form 'float' above the MDI form
  135.         Call SetWindowWord(Me.hwnd, SWW_HPARENT, MDIForm1.hwnd)
  136.     End If
  137.     'reset the moving flag and store the form dimensions
  138.     bMoving = False
  139.     StoreFormDimensions
  140. End Sub
  141. Private Sub FormDragger1_FormMoved(FormLeft As Long, FormTop As Long, FormWidth As Long, FormHeight As Long)
  142.     Dim rct As RECT
  143.     'Set the moving flag so we dont store the wrong dimensions
  144.     bMoving = True
  145.     'If over Picture1 on MDIForm1 which we are using as a Dock, change the width to that of
  146.     'Picture1, else change it to the 'floating width and height
  147.     'For the purposes of this example, we only dock if the top left corner
  148.     'of this form is within the area bounded by Picture1
  149.     'Get the screen based coordinates of Picture1
  150.     GetWindowRect MDIForm1!Picture1.hwnd, rct
  151.     'Inflate the rect because we want the form to be bigger than Picture1
  152.     'to hide it's border
  153.     With rct
  154.         .Left = .Left - 4
  155.         .Top = .Top - 4
  156.         .Right = .Right + 4
  157.         .Bottom = .Bottom + 4
  158.     End With
  159.     'See if the top/left corner of this form is in Picture1's screen rectangle
  160.     If PtInRect(rct, FormLeft, FormTop) Then
  161.         FormWidth = lDockedWidth / Screen.TwipsPerPixelX
  162.         FormHeight = lDockedHeight / Screen.TwipsPerPixelY
  163.     Else
  164.         FormWidth = lFloatingWidth / Screen.TwipsPerPixelX
  165.         FormHeight = lFloatingHeight / Screen.TwipsPerPixelY
  166.     End If
  167. End Sub
  168. Private Sub StoreFormDimensions()
  169.    'Store the height/width values
  170.     If Not bMoving Then
  171.         If bDocked Then
  172.             lDockedWidth = Me.Width
  173.             lDockedHeight = Me.Height
  174.         Else
  175.             lFloatingLeft = Me.Left
  176.             lFloatingTop = Me.Top
  177.             lFloatingWidth = Me.Width
  178.             lFloatingHeight = Me.Height
  179.         End If
  180.     End If
  181. End Sub
  182.